<?php

namespace App\Http\Controllers\Index\Users;

use App\Http\Controllers\Controller;
use App\Models\User;
use UsersShow;
use UsersUpdate;
use App\Http\Requests\Index\Users\UpdateUsersRequest;
use App\Handlers\ImageUploadHandler;

class UsersController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth', [
            'except' => ['show', 'create', 'store', 'index']
        ]);

    }
    public function index()
    {
        $users =  UsersShow::user_index(10);
        return view('index.users.index', compact('users'));
    }
    public function show(User $user)
    {
        $statuses = UsersShow::user_statuses($user);
        return view('index.users.show',compact('user', 'statuses'));
    }

    public function edit(User $user)
    {
        $this->authorize('update', $user);
        return view('index.users.edit', compact('user'));
    }
    public function update(User $user, UpdateUsersRequest $request,ImageUploadHandler $uploader)
    {
        $this->authorize('update', $user);
        UsersUpdate::user_store($request,$user,$uploader);
        return redirect()->route('users.show', $user);
    }
    /*
     * 关注人
     * */
    public function followings(User $user)
    {
        $users = UsersShow::follower($user,1);
        return view('index.users.show_follow',['users'=>$users['user'],'title'=>$users['title']]);
    }
    /*
     * 被关注
     * */
    public function followers(User $user)
    {
        $users = UsersShow::follower($user,2);
        return view('index.users.show_follow',['users'=>$users['user'],'title'=>$users['title']]);
    }
}
